package com.ncloud.resman.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.alibaba.fastjson.JSONObject;

@Mapper
public interface DeviceMapMapper{

	@Select("SELECT room_id, room_name, "
			+ "CONCAT(area_id,'') as area_id, area_name, "
			+ "CONCAT(country_id,'') as country_id,country_name, "
			+ "CONCAT(province_id,'') as province_id,province_name, "
			+ "CONCAT(city_id,'') as city_id, city_name, addr, room_type, "
			+ "(select dict_value from sys_dictionary t1 where dictionary_id = 'room_type' and t1.dict_key=t.room_type) as room_type_name,"
			+ "room_state, contact_person, contact_phone FROM sys_computer_room t "
			+ "where room_id = #{0}")
	@Results({
		@Result(column="room_id",property="roomId"),@Result(column="room_name",property="roomName"),
		@Result(column="area_id",property="areaId"),@Result(column="area_name",property="areaName"),
		@Result(column="country_id",property="countryId"),@Result(column="country_name",property="countryName"),
		@Result(column="province_id",property="provinceId"),@Result(column="province_name",property="provinceName"),
		@Result(column="city_id",property="cityId"),@Result(column="city_name",property="cityName"),
		@Result(column="addr",property="addr"),@Result(column="room_type",property="roomType"),
		@Result(column="room_type_name",property="roomTypeName"),
		@Result(column="room_state",property="roomState"),@Result(column="contact_person",property="contactPerson"),
		@Result(column="contact_phone",property="contactPhone")})
	List<JSONObject> getRoomInfoById(Integer roomId);//机房信息
	@Select("SELECT t1.cabinet_id, ifnull(t1.device_id,0) as device_id, "
			+ "ifnull(t2.sn_num,'') as sn_num,t1.use_num, t1.state, "
			+ "ifnull(t2.eqpt_type,'') as eqpt_type,ifnull(t2.type_name,'') as type_name "
			+ "FROM res_cabinet_use t1 left join res_device_base t2 on t1.device_id=t2.device_id "
			+ "where t1.cabinet_id =#{0} order by use_num ")
	@Results({
		@Result(column="cabinet_id",property="cabinetId"),@Result(column="device_id",property="deviceId"),
		@Result(column="sn_num",property="snNum"),@Result(column="use_num",property="useNum"),@Result(column="state",property="state"),
		@Result(column="eqpt_type",property="eqptType"),@Result(column="type_name",property="typeName")})
	List<JSONObject> getCabinetUseById(Long cabinetId);//机房信息
}
